// pages/ProgrammeMansge/ProgrammeMansge.js
const DB = wx.cloud.database();
const foodCenter = DB.collection("FoodCenter");
const foodCrd = DB.collection("FoodCRD");
const foodOut = DB.collection("FoodOut");
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  set(e) {
    console.log(e)

    let _sqltype = e.detail.value.sqltype
    let _img = e.detail.value.img
    let _title = e.detail.value.foodTitle
    let _describe = e.detail.value.describe
    let _weight = e.detail.value.weight

    let _briefIntr = e.detail.value.briefIntr
    let _mainfood = e.detail.value.mainfood

    let _drink = e.detail.value.drink

    let _foods = e.detail.value.foods
    if (_sqltype == "FoodCenter") {
      console.log(_sqltype)
      foodCenter.add({
        data: {
          img: _img,
          title: _title,
          describe: _describe,
          weight: _weight,
          briefIntr: _briefIntr,
          mainfood: _mainfood,
          drink: _drink,
          foods: _foods
        }
      })
    }

    else if(_sqltype == "FoodCRD"){
      console.log(_sqltype)
      foodCrd.add({
        data: {
          img: _img,
          title: _title,
          describe: _describe,
          weight: _weight,
          briefIntr: _briefIntr,
          mainfood: _mainfood,
          drink: _drink,
          foods: _foods
        }
      })
    }
    else if(_sqltype == "FoodOut"){
      console.log(_sqltype)
      foodOut.add({
        data: {
          img: _img,
          title: _title,
          describe: _describe,
          weight: _weight,
          briefIntr: _briefIntr,
          mainfood: _mainfood,
          drink: _drink,
          foods: _foods
        }
      })
    }
    wx.showToast({
      title: '添加成功'
    })
  }
})